<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/assets/css/admin.css">
</head>

<body>
  <div class="login">
    <div class="login-wrap">
      <img class="avatar" src="/assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <div class="alert alert-danger" style="display:none" id="alert">
        <strong>错误！</strong>
        <span id="errno"></span>！
      </div>
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" class="form-control" placeholder="密码">
      </div>
      <button class="btn btn-primary btn-block" id="loginBtn">登 录</button>
    </div>
  </div>
</body>
<script src="\assets\vendors\jquery\jquery.min.js"></script>
<script src='../assets/vendors/axios.min.js'></script>
<script>
  $(function () {

    $('#loginBtn').on('click', function () {
      var email = $('#email').val();
      var password = $('#password').val();
      if (email.trim().length == 0) {
        $('#alert').css('display', 'block')
        $('#errno').html('请输入用户名')
        return;
      } else {
        $('#alert').css('display', 'none')
      }
      if (password.trim().length == 0) {
        $('#alert').css('display', 'block')
        $('#errno').html('请输入密码')
        return;
      } else {
        $('#alert').css('display', 'none')
      }


      axios.post('/login', {
          email: email,
          password: password
        })
        .then(function (res) {
          sessionStorage.setItem('curUser',res.data._id)
          location.href = '/admin/index.html'
        
        })
        .catch(function (error) {
          $('#alert').css('display', 'block')
          $('#errno').html('用户名或者密码错误')
        });
    })


  })
</script>

</html>